<!DOCTYPE html>
<?php 
require_once dirname(__FILE__).'/Controller.php';
$allowEditFlg = Editor_Controller::isAllowEdit();
$htmlFileName = '';
$htmlTitle = '';
$contents = '';
	if (isset($_REQUEST['editor1'])){
		if ($_REQUEST['editor1'] != '') {
			$contents = $_REQUEST['editor1'];
		}
	} else if (isset($_REQUEST['load'])) {
		$fileName = dirname(__FILE__) . '/../contents/' . $_REQUEST['load'];
		if (file_exists($fileName)) {
			$contents = Editor_Controller::getFromBodyToBody($fileName);
			$htmlFileName = $_REQUEST['load'];
			$htmlTitle = Editor_Controller::getTitleFromHtmlFile($fileName);
		}
	} else {
		$contents = file_get_contents(dirname(__FILE__).'/template1.txt');
	}
?>
<html>
<head>
	<title>Life hack 資料編集画面</title>
	<meta charset="utf-8">
	<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
	<script src="../ckeditor.js"></script>
	<link href="../my.css" rel="stylesheet">
	<script type="text/javascript">
	$(function() {
		$("#button-preview").click(function(){
//			$("#preview").load("mypreview.php",{editor1:$('#editor1').val()});
//			alert(document.commit.target); 
			document.commit.target = "preview";
			document.commit.action = 'preview.php';
			document.commit.submit();
			document.commit.target = "_self";
		});
		$("#button-save").click(function(){
			document.commit.target = "preview";
			document.commit.action = 'modify.php';
			document.commit.submit();
			document.commit.target = "_self";
		});
	});
</script>
</head>
<body>
	<h1 class="samples">
		Life hack 資料編集画面
	</h1>
	<form action="sample_posteddata.php" method="post" name="commit" target="_self" id="comm">
		<div style="padding-bottom: 10px;">ページタイトル：<input type="text" name="pagetitle" style="width:300px" value="<?php echo $htmlTitle;?>" /></div>
		<div class="description">
			<p style="display: none">
				This editor is using an <code>&lt;iframe&gt;</code> element-based editing area, provided by the <strong>Wysiwygarea</strong> plugin.
			</p>
<pre class="samples" style="display: none">
CKEDITOR.replace( '<em>textarea_id</em>' )
</pre>
		</div>
		<textarea cols="40" id="editor1" name="editor1" rows="10">
			<?php echo $contents;?>
		</textarea>
		<script>

			// This call can be placed at any point after the
			// <textarea>, or inside a <head><script> in a
			// window.onload event handler.

			// Replace the <textarea id="editor"> with an CKEditor
			// instance, using default configurations.

			CKEDITOR.replace( 'editor1' );

		</script>
		<p>
			<input type="button" value="SAVE" id="button-save"
				<?php if (!Editor_Controller::isAllowEdit()){?>DISABLED<?php }?>
			 />
			<input type="button" value="PREVIEW" id="button-preview" />
			<input type="text" name="filename" value="<?php echo $htmlFileName;?>" />
		</p>
	</form>
		<ht />
	<div id="footer">
		 Site admin:
		<a href="https://plus.google.com/114123801910840146383/posts/p/pub#114123801910840146383/posts">SHINICHI HARIU</a>
		<p>Copyright (C) 2013 copyrights.shichini hariu All Rights Reserved. </p>
	</div>
</body>
</html>
